<?php
/**
 * Created by PhpStorm.
 * User: joe
 * Date: 2019-12-13
 * Time: 1:09
 */

namespace app\common\bean\builder;

/**
 * 类似java的StringBuilder
 * Class StringBuilder
 * @package app\common\bean\builder
 */
class StringBuilder
{
    private $content = '';

    /**
     * 获取封装的字符串内容
     * @return string
     */
    public function getContent()
    {
        return $this->content;
    }


    /** 拼接字符串并换行和tab
     * @param $concat
     * @param int $tabCount
     * @param int $entCount
     * @return StringBuilder
     */
    public function concatStringEnter($concat, $tabCount = 1,$entCount = 1)
    {
//        $this->content .= $tabCount >= 0 ? str_repeat("\t", $tabCount) : str_repeat("\b", abs($tabCount));
        $this->content .= str_repeat("\t", $tabCount);
        $this->content .= $concat . str_repeat("\n", $entCount);
        return $this;
    }

    /** 生成制表符
     * @param int $count
     * @return StringBuilder
     */
    public function getTab($count = 1)
    {
        $this->content .= str_repeat("\t", $count);
        return $this;
    }

    /** 生成回车符
     * @param int $count
     * @return StringBuilder
     */
    public function getEnter($count = 1)
    {
        $this->content .= str_repeat("\n", $count);
        return $this;
    }
}